package com.dayangxiaoen.pms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dayangxiaoen.pms.mapper.ExchangeAmountMapper;
import com.dayangxiaoen.pms.mapper.LogInfoMapper;
import com.dayangxiaoen.pms.po.ExchangeAmount;
import com.dayangxiaoen.pms.po.LogInfo;
import com.dayangxiaoen.pms.service.ExchangeAmountService;
import com.dayangxiaoen.pms.service.LogInfoService;
import com.dayangxiaoen.pms.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.List;

/**
 * @author dayangxiaoen
 */
@Service
public class ExchangeAmountServiceImpl extends ServiceImpl<ExchangeAmountMapper, ExchangeAmount> implements ExchangeAmountService {

    @Autowired
    private ExchangeAmountMapper exchangeAmountMapper;

    @Override
    public Result findExchangeAmountByDays(Integer days) {

        LocalDate now = LocalDate.now();
        LocalDate localDate = now.minusDays(days);


        LambdaQueryWrapper<ExchangeAmount> wrapper = new LambdaQueryWrapper<ExchangeAmount>();
        wrapper.ge(ExchangeAmount::getDate,localDate);
        wrapper.le(ExchangeAmount::getDate,now);

        List<ExchangeAmount> exchangeAmounts = exchangeAmountMapper.selectList(wrapper);

        return Result.sucess(exchangeAmounts,"获取销售量成功");

    }
}
